package com.fresh.wx.utils;


import net.sf.json.JSONObject;

/**
 * 订单发货提醒推送微信消息
 *
 */
public class WXOrderMsgTemplete implements Runnable {
	
	private String openId;
	private String title;
	private String date;
	private String  productName;
	private String  orderDetail;
	private String  remark;
	
	/**
	 * 异步发送微信模板
	 * @param openId
	 * @param title  标题 
	 * @param date  提醒时间
	 * @param productName     商品名称
	 * @param orderDetail         订单描述
	 * @param remark         备注
	 */
	public  WXOrderMsgTemplete(
			String openId, 
			String title,
			String date,
			String  productName,
			String  orderDetail,
			String  remark){
	       this.openId =openId;
		   this.title = title;
		   this.date = date;
		   this.productName =productName; 
		   this.orderDetail =orderDetail;
		   this.remark = remark;
	}

	/**
	 * 发送微信模板消息
	 * @param openId
	 * @param title
	 * @param sendDate
	 * @param pack
	 */
	public static void sendTmp( 
			String openId,
			String title,
			String date,
			String  productName,
			String  orderDetail,
			String  remark){
		
		String URL = "https://api.weixin.qq.com/cgi-bin/message/template/send?access_token="+WXConfig.TOKEN;
		
		String json ="{";
		json+=   "\"touser\":\""+openId+"\",";
		json+=   "\"template_id\":\"0gy_Axmtd70n7WLMZTgON_hs0rEUhSP9bUxsN0jBc7I\",";
		json+=   "\"url\":\"http://zx.leadfresh.cn/fresh-cloud-api/buyer/index\",";  
		json+=   "\"data\":{";
		json+=    "\"first\": {";
		json+=                     "\"value\":\""+title+"！\",";
		json+=                     "\"color\":\"#173177\"";
		json+=                  "},";
		json+=     "\"keyword1\":{";
		json+=                   "\"value\":\""+date+"\",";
		json+=                   "\"color\":\"#173177\"";
		json+=                   "},";
		json+=       "\"keyword2\": {";
		json+=                 "\"value\":\""+productName+"\",";
		json+=                 "\"color\":\"#173177\"";
		json+=             "},";
		json+=       "\"keyword3\": {";
		json+=                 "\"value\":\""+orderDetail+"\",";
		json+=                 "\"color\":\"#173177\"";
		json+=             "},";
        json+=      "\"remark\":{";
        json+=                 "\"value\":\""+remark+"\",";
        json+=                  "\"color\":\"#173177\"";
        json+=           "}";
        json+=      "}";
        json+=  "}";
		
        System.out.println(json);
		
		JSONObject jsonObject = CommonUtil.httpsRequest(URL, "POST", json);
		System.out.println("jsonObject    : "+jsonObject);
		
	}
	
	@Override
	public void run() {
		// TODO Auto-generated method stub
		//发送微信模板推送 
		sendTmp(openId, title, date, productName,orderDetail,remark);
	}
	
}
